﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using WechatUtility;

namespace WechatDAL
{
    public class EncryptDal
    {
        /// <summary>
        /// 公众号消息解密
        /// </summary>
        /// <param name="signature"></param>
        /// <param name="timestamp"></param>
        /// <param name="nonce"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public int DecPublic(string signature, string timestamp, string nonce, string data, ref string result)
        {
            result = "";
            WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(WechatAPI4Public.Token, WechatAPI4Public.AESKey, WechatAPI4Public.AppID);
            return wxcpt.DecryptMsg(signature, timestamp, nonce, data, ref result);
        }

        /// <summary>
        /// 企业号接入认证
        /// </summary>
        /// <param name="signature"></param>
        /// <param name="timestamp"></param>
        /// <param name="nonce"></param>
        /// <param name="echoStr"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public int EntCheckIn(string signature, string timestamp, string nonce, string echoStr, ref string result)
        {
            result = "";
            WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(WechatAPI4Ent.Token, WechatAPI4Ent.AESKey, WechatAPI4Ent.CorpID);
            int ret = 0;
            ret = wxcpt.VerifyURL(signature, timestamp, nonce, echoStr, ref result);
            return ret;
        }
    }
}
